/**
 * 
 */
package com.thon.dao.user.impl;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.thon.dao.user.MessageDao;
import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.user.Message;

/**
 * @file MessageDaoImpl.java
 * @author Zemo
 * @email zemochen@lanbaoo.com
 * @date 2013年12月10日 下午10:23:18
 * @description TODO
 */
@Repository
public class MessageDaoImpl extends AbstractDao<Message> implements MessageDao{
	
	public MessageDaoImpl(){
		super(Message.class);
	}

	@Override
	public List<Message> listAllMessages() {
		String querysString = "From Message";
		return findList(querysString, null);
	}

	@Override
	public Page<Message> findMessagesPage(Page<Message> page, int userId) {
		String queryString = "FROM Message m where m.messageTo.id = ? order by m.createdDate desc";
		
		return findPage(page, queryString, userId);
	}

	@Override
	public Long countMessage(Integer userId) {
		
		String queryString = "SELECT COUNT(*) FROM Message WHERE readTime = NULL AND messageTo.id=?";
		return count(queryString, userId);
	}

}
